﻿using BusinessLogicLayer;
using DevComponents.DotNetBar.Controls;
using Equin.ApplicationFramework;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PresentationLayer
{
    public partial class FormChiTietOnSite : Form
    {
        public OnSite onsite { get; set; }
        public FormChiTietOnSite()
        {
            InitializeComponent();
          
        }

        private void FormChiTietOnSite_Load(object sender, EventArgs e)
        {
            
            txtMaOnSite.Text = onsite.MaOnSite.ToString();
            txtCongTy.Text = onsite.CongTy.ToString();
            txtDiaDiem.Text = onsite.DiaDiem.ToString();
            txtNgayBD.Text = onsite.NgayBD.ToShortDateString().ToString();
            txtNgayKT.Text = onsite.NgayKT.ToShortDateString().ToString();
            //
            dgvChitiet.AllowUserToAddRows = false;
            dgvChitiet.AllowUserToDeleteRows = false;
            dgvChitiet.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgvChitiet.BackgroundColor = Color.FromArgb(76, 133, 188);
            dgvChitiet.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            dgvChitiet.MultiSelect = false;
            dgvChitiet.ReadOnly = true;
            dgvChitiet.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgvChitiet.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn colMaNV = new DataGridViewTextBoxColumn();
            colMaNV.HeaderText = "Mã nhân viên";
            colMaNV.DataPropertyName = "MaNhanVien";
            colMaNV.Name = "MaNhanVien";

            DataGridViewTextBoxColumn colHoNV = new DataGridViewTextBoxColumn();
            colHoNV.HeaderText = "Họ nhân viên";
            colHoNV.DataPropertyName = "HoNhanVien";
            colHoNV.Name = "HoNhanVien";

            DataGridViewTextBoxColumn colTenNV = new DataGridViewTextBoxColumn();
            colTenNV.HeaderText = "Tên nhân viên";
            colTenNV.DataPropertyName = "TenNhanVien";
            colTenNV.Name = "TenNhanVien";

            DataGridViewTextBoxColumn colDiaChi = new DataGridViewTextBoxColumn();
            colDiaChi.HeaderText = "Địa chỉ";
            colDiaChi.DataPropertyName = "DiaChi";
            colDiaChi.Name = "DiaChi";

            if (dgvChitiet.Columns.Count == 0)
                dgvChitiet.Columns.AddRange(new DataGridViewColumn[] { colMaNV,colHoNV, colTenNV,colDiaChi });
            ActionResultAsList<NhanVien> rs = new OnSiteManager().LayDSNhanVienTheoMaOnSite(onsite.MaOnSite);
            if (rs.Success)
            {
                dgvChitiet.DataSource = new BindingListView<NhanVien>(rs.ObjectList);
                lblTongSoDongNVOnSite.Text = "Tổng số dòng: " + dgvChitiet.RowCount;
            }
            else
                MessageBox.Show("Xảy ra lỗi!\n\nChi tiết: " + rs.Exceptions[rs.Exceptions.Count - 1].Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
         
        }
    }
}
